package com.harry.hr.biz.impl;

import java.util.List;

import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;

import com.harry.hr.biz.UserBIZ;
import com.harry.hr.dao.UserDAO;
import com.harry.hr.entity.system.User;

public class UserBIZImpl implements UserBIZ{
	private UserDAO userDAO;
	
	public void setUserDAO(UserDAO userDAO){
		this.userDAO = userDAO;
	}

	public boolean signCheck(User user) {
		return userDAO.query(user, MatchMode.EXACT, null).size()>0;
	}
	public User getUser(User user) {
		return userDAO.query(user, MatchMode.EXACT, null).get(0);
	}
	public List<User> query(User user) {
		// TODO Auto-generated method stub
		List<User> ulist=userDAO.query(user, MatchMode.ANYWHERE, Order.asc("id"));
		return ulist;
	}

	public boolean addUser(User user) {
		// TODO Auto-generated method stub
		 
		try
		{	
			userDAO.save(user);
			return true;
		}catch(Exception ex){
	
			return false;
			}
	}

	public boolean delUser(int id) {
		// TODO Auto-generated method stub
		try{
			userDAO.del(id);
			return true;
		}catch(Exception e){
			return false;
		}
	}

	public List<User> showUser() {
		// TODO Auto-generated method stub
		List<User> ulist=userDAO.findAll();
		return ulist;
	}

	public boolean updateUser(User user) {
		// TODO Auto-generated method stub
		try
		{
			userDAO.update(user);
			return true;
		}catch(Exception e)
		{
			return false;
		}
	}

	public User findByid(int id) {
		
		return userDAO.findByid(id);
	}

	public boolean isExsist(String name) {
		// TODO Auto-generated method stub
		List<User> list=userDAO.Search(name);
		if(list.size()>0||list==null)
		{
			return true;
		}
		return false;
	}
}
